package com.emmmya.ocs.common.utils;

import lombok.Data;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @description: shiro的配置类
 * @author: 咕噜肉IT小店-黑医
 * @createDate: 2020-05-13
 * @version: 1.0
 */
@Component
@ConfigurationProperties("config.shiro")
@Data
public class ShiroUtil {

    private String algorithm;

    private String salt;

    private String count;

    private List<String> anon;

    /**
     * 允许get请求携带token的地址
     */
    private List<String> allowGet;

    public String encryptionToHex(String password){
        SimpleHash simpleHash = new SimpleHash(algorithm,password,salt,Integer.valueOf(count));
        String s = simpleHash.toHex();
        return s;
    }
    public String encryptionToBase64(String password){
        SimpleHash simpleHash = new SimpleHash(algorithm,password,salt,Integer.valueOf(count));
        String s = simpleHash.toBase64();
        return s;
    }

    public static void main(String[] args) {
        SimpleHash simpleHash = new SimpleHash("md5","Shuwen123!","c0a63feebc0dbe5cccf62deb39250ab4",100);
        String s = simpleHash.toHex();
        System.out.println(s);
    }
}
